﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.IO;
using System.Diagnostics;

namespace data
{
    class Program
    {
        static void Main(string[] args)
        {

            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(@"C:\Documents and Settings\Administrator\桌面\ab.kml");
            System.Xml.XmlNamespaceManager nsmgr = new System.Xml.XmlNamespaceManager(xmlDoc.NameTable);
            nsmgr.AddNamespace("wms", "http://www.opengis.net/kml/2.2");
            
            StreamWriter sw = File.CreateText(@"c:\hzbuslink.txt");
            for (int i = 1; i < 100; i++)
            {
                XmlNode nodea = xmlDoc.SelectSingleNode("wms:kml/wms:Document/wms:Folder/wms:Placemark[wms:name='a" + i + "']//wms:coordinates", nsmgr);
                if (nodea != null)
                {
                    XmlNode nodeb = xmlDoc.SelectSingleNode("wms:kml/wms:Document/wms:Folder/wms:Placemark[wms:name='b" + i + "']//wms:coordinates", nsmgr);
                    if (nodeb != null)
                    {
                        sw.WriteLine(i + "\t" + nodea.InnerText.Replace(",0", "").Replace(',', '\t') + "\t" + nodeb.InnerText.Replace(",0", "").Replace(',', '\t'));
                    }
                    else
                    {
                        Console.WriteLine(i + "b");
                        Debug.WriteLine(i + "b");
                    }
                }
                else
                {
                    Console.WriteLine(i + "a");
                    Debug.WriteLine(i + "a");
                }
            }
            sw.Flush();
            sw.Close();
        }
    }
}
